package real.yingke;
import java.util.*;


public class ParseUrl {
    /**
     * url解析
     * @param neturl string字符串 
     * @return string字符串一维数组
     * "https://www.uvideo.com:8888/watch?v=XG0CFDPGGqc&c=browser#section1"
     * ["https","www.uvideo.com","8888","/watch","v=XG0CFDPGGqc&c=browser","section1"]
     */
    public static String[] UrlParsing (String neturl) {
        List<String> res = new ArrayList<>();
        String[] strs = neturl.split(":"); //   https   //www..com    8888/watch...
        res.add(strs[0]);
        strs[1] = strs[1].substring(2);
        res.add(strs[1]);
        // System.out.println(res);
        String[] pp = strs[2].split("/"); // 8888     /watch?v=XG0CFDPGGqc&c=browser#section1
        res.add(pp[0]); //8888
        // System.out.println(res);
        pp[1] = "/" + pp[1]; //  /watch?v=XG0CFDPGGqc&c=browser#section1
        // String[] sufs = pp[1].split("?");
        // System.out.println(pp[1]);
        int idx = 0;
        for (int i = 0; i < pp[1].length(); i++) {
            if (pp[1].charAt(i) == '?') {
                idx = i;
                break;
            }
        }
        String sufs0 = pp[1].substring(0, idx), sufs1 = pp[1].substring(idx + 1);

        res.add(sufs0);
        // System.out.println(res);
        String[] params = sufs1.split("#"); //v=XG0CFDPGGqc&c=browser#section1
        res.add(params[0]);
        res.add(params[1]);
        return res.toArray(new String[res.size()]);
    }

    public static void main(String[] args) {
        String[] res = UrlParsing("https://www.uvideo.com:8888/watch?v=XG0CFDPGGqc&c=browser#section1");
        System.out.println(Arrays.toString(res));
    }
}